package siau.android.base

import android.content.Context
import siau.android.base.enum.HeightClass

fun analyseDataBeforeSet(data: String, pageType: Int, defaultClass: String): String {
    return if (SBApplication.userData.heightUnit == HeightClass.FT.msg && pageType == 2) {
        if (data.contains(".")) {
            val split = data.split(".")
            if (split[0].toInt() == 0) {
                if (split[1].length == 1 && split[1].toInt() == 1) {
                    "10in"
                } else {
                    "${split[1].toInt()}in"
                }
            } else {
                if (split[1].toInt() == 0) {
                    split[0] + "ft"
                } else {
                    if (split[1].length == 1 && split[1].toInt() == 1) {
                        split[0] + "ft10in"
                    } else {
                        split[0] + "ft" + split[1].toInt() + "in"
                    }
                }
            }
        } else {
            data + "ft"
        }
    } else {
        data + defaultClass
    }
}

fun analyseHomeDataBeforeSet(context: Context, data: String, pageType: Int, defaultClass: String): String {
    val bigSize = dp2px(context, 40f)
    val smallSize = dp2px(context, 16f)
    return if (SBApplication.userData.heightUnit == HeightClass.FT.msg && pageType == 2) {
        if (data.contains(".")) {
            val split = data.split(".")
            if (split[0].toInt() == 0) {
                if (split[1].length == 1 && split[1].toInt() == 1) {
                    "<div><homeFont size='${bigSize}px'>10</homeFont><homeFont size='${smallSize}px'>in</homeFont></dic>"
                } else {
                    "<div><homeFont size='${bigSize}px'>${split[1].toInt()}</homeFont><homeFont size='${smallSize}px'>in</homeFont></div>"
                }
            } else {
                if (split[1].toInt() == 0) {
                    "<div><homeFont size='${bigSize}px'>${split[0]}</homeFont><homeFont size='${smallSize}px'>ft</homeFont></div>"
                } else {
                    if (split[1].length == 1 && split[1].toInt() == 1) {
                        "<div><homeFont size='${bigSize}px'>${split[0]}</homeFont><homeFont size='${smallSize}px'>ft</homeFont><homeFont size='${bigSize}px'>10</homeFont><homeFont size='${smallSize}px'>in</homeFont></div>"
                    } else {
                        "<div><homeFont size='${bigSize}px'>${split[0]}</homeFont><homeFont size='${smallSize}px'>ft</homeFont><homeFont size='${bigSize}px'>${split[1].toInt()}</homeFont><homeFont size='${smallSize}px'>in</homeFont></div>"
                    }
                }
            }
        } else {
            "<div><homeFont size='${bigSize}px'>$data</homeFont><homeFont size='${smallSize}px'>ft</homeFont></div>"
        }
    } else {
        "<div><homeFont size='${bigSize}px'>$data</homeFont><homeFont size='${smallSize}px'>$defaultClass</homeFont></div>"
    }
}